Skip to content

Add ToDictionary extensions on IDictionary#41

Merged
Tyrrrz merged 7 commits intoprimefrom
copilot/add-todictionary-implementation
Apr 17, 2026
Merged

Add ToDictionary extensions on IDictionary#41
Tyrrrz merged 7 commits intoprimefrom
copilot/add-todictionary-implementation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Ports ToDictionary extensions from CliFx, enabling typed conversion of a non-generic IDictionary to Dictionary<TKey, TValue>.

Changes

  • DictionaryExtensions.cs: New file with an extension(IDictionary) block containing two overloads:
    • ToDictionary<TKey, TValue>(IEqualityComparer<TKey> comparer) — casts each DictionaryEntry to the typed key/value pair and delegates to Enumerable.ToDictionary with the given comparer.
    • ToDictionary<TKey, TValue>() — uses EqualityComparer<TKey>.Default as the comparer.
  • DictionaryExtensionsTests.cs: Covers result type, comparer identity, and key/value contents for both overloads.

Usage

IDictionary raw = new Hashtable { ["one"] = 1, ["two"] = 2 };

// With explicit comparer
Dictionary<string, int> typed = raw.ToDictionary<string, int>(StringComparer.OrdinalIgnoreCase);

// With default comparer
Dictionary<string, int> typed = raw.ToDictionary<string, int>();

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/1fae76cb-448e-4220-a83e-af9cc4b1b09f

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 17, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 17, 2026 06:57
Copilot AI review requested due to automatic review settings April 17, 2026 06:57
Comment thread PowerKit/Extensions/CollectionExtensions.cs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.61%. Comparing base (667c235) to head (bfd71bf).
⚠️ Report is 5 commits behind head on prime.

Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #41      +/-   ##
==========================================
+ Coverage   94.47%   94.61%   +0.14%     
==========================================
  Files          76       80       +4     
  Lines        1574     1615      +41     
  Branches      131      134       +3     
==========================================
+ Hits         1487     1528      +41     
  Misses         65       65              
  Partials       22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/3c3b48e0-603c-41b3-8245-6705e3af60e8

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI changed the title Add ToDictionary extension on IDictionary Add ToDictionary extensions on IDictionary Apr 17, 2026
Copilot AI requested a review from Tyrrrz April 17, 2026 06:59
Comment thread PowerKit/Extensions/CollectionExtensions.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new ToDictionary<TKey, TValue>(IEqualityComparer<TKey>) extension for non-generic IDictionary, enabling conversion into a typed Dictionary<TKey, TValue> while allowing the caller to control key comparison semantics.

Changes:

  • Added an extension(IDictionary) block with ToDictionary<TKey, TValue>(IEqualityComparer<TKey>) in CollectionExtensions.
  • Added a new xUnit test covering IDictionaryDictionary<TKey, TValue> conversion behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
PowerKit/Extensions/CollectionExtensions.cs Introduces IDictionary.ToDictionary<TKey, TValue>(comparer) conversion implemented via DictionaryEntry + LINQ ToDictionary.
PowerKit.Tests/CollectionExtensionsTests.cs Adds test coverage for the new ToDictionary extension.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit.Tests/CollectionExtensionsTests.cs Outdated
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/7b2e1cff-8093-4d46-84c6-ee49c7deaa4d

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI requested a review from Tyrrrz April 17, 2026 07:03
Comment thread PowerKit.Tests/DictionaryExtensionsTests.cs Outdated
Comment thread PowerKit/Extensions/DictionaryExtensions.cs Outdated
…nalIgnoreCase in custom comparer test

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/3911b564-c5f7-4c05-8e2a-a968a65f9d65

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Comment thread PowerKit.Tests/DictionaryExtensionsTests.cs Outdated
Copilot AI requested a review from Tyrrrz April 17, 2026 07:53
Comment thread PowerKit.Tests/DictionaryExtensionsTests.cs Outdated
Copilot AI requested a review from Tyrrrz April 17, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants